﻿using System;
using System.Collections.Generic;

class AllVariationsOfK

            // Write a program that reads two numbers N and K and generates all the variations of K elements from the set [1..N]. Example:
	        // N = 3, K = 2  {1, 1}, {1, 2}, {1, 3}, {2, 1}, {2, 2}, {2, 3}, {3, 1}, {3, 2}, {3, 3}

{
    static void Main()
    {
        Console.Write("Enter the value of 'N': ");
        int n = int.Parse(Console.ReadLine());
        Console.Write("Enter the value of 'K': ");
        int k = int.Parse(Console.ReadLine());
        int index = k - 1;
        int previousVal = 0;
        Console.WriteLine();

        List<int> values = new List<int>();
        for (int i = 0; i < k; i++) values.Add(1);

        while (true)
        {
            while (index > -1 && values[index] == n)
            {
                previousVal = values[index];
                values[index] = 1;
                --index;
            }
            if (index == -1 && previousVal == n)
            {
                break;
            }

            ++values[index];
            index = k - 1;
            foreach (int item in values) Console.Write(item + " ");
            Console.WriteLine();
        }
    }
}
